package com.gitee.elead.model.serializer;

import java.io.IOException;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.gitee.elead.util.ApplicationUtils;

/**
 * 数据库查询的用户id缓存用户名称
 * 
 * @author luopeng
 *
 */
public class UserJsonSerializer extends JsonSerializer<String> {

	private IUserJsonSerializerService userJsonSerializerService;

	@Override
	public void serialize(String value, JsonGenerator generator, SerializerProvider serializers) throws IOException {
		if (ObjectUtils.isEmpty(userJsonSerializerService)) {
			userJsonSerializerService = ApplicationUtils.getBean(IUserJsonSerializerService.class);
		}
		generator.writeString(userJsonSerializerService.getUserName(value));
	}

}
